import { ApiProperty } from '@nestjs/swagger';
import {
  IsString,
  IsOptional,
  MaxLength,
  IsDateString,
  IsNumber,
} from 'class-validator';
import { Type } from 'class-transformer';
import { Gender, SingerType } from './singer.entity';
import { AlbumResponseDto } from '../album/album.dto';
import { SongResponseDto } from '../song/song.dto';

// 创建歌手DTO
export class CreateSingerDto {
  @ApiProperty({
    description: '歌手名称',
    example: '周杰伦',
    maxLength: 50,
  })
  @IsString()
  @MaxLength(50)
  name: string;

  @ApiProperty({
    description: '歌手描述',
    example: '华语流行音乐男歌手、词曲创作人、演员',
    required: false,
    maxLength: 5000,
  })
  @IsOptional()
  @IsString()
  @MaxLength(5000)
  description?: string;

  @ApiProperty({
    description: '歌手头像URL',
    example: 'https://example.com/avatar.jpg',
    required: false,
  })
  @IsOptional()
  @IsString()
  avatarUrl?: string;

  @ApiProperty({
    description: '出生日期',
    example: '1979-01-18',
    required: false,
  })
  @IsOptional()
  @IsDateString()
  birthDate?: string;

  @ApiProperty({
    description: '国籍',
    example: '中国台湾',
    required: false,
    maxLength: 100,
  })
  @IsOptional()
  @IsString()
  @MaxLength(100)
  nationality?: string;

  @ApiProperty({
    description: '歌手性别',
    example: 'male',
    enum: Gender,
    required: false,
  })
  @IsOptional()
  gender?: Gender;

  @ApiProperty({
    description: '歌手类型',
    example: 'pop',
    enum: SingerType,
    required: false,
    default: SingerType.POP,
  })
  @IsOptional()
  type?: SingerType;
}

// 更新歌手DTO
export class UpdateSingerDto {
  @ApiProperty({
    description: '歌手名称',
    example: '周杰伦',
    required: false,
    maxLength: 50,
  })
  @IsOptional()
  @IsString()
  @MaxLength(50)
  name?: string;

  @ApiProperty({
    description: '歌手描述',
    example: '华语流行音乐男歌手、词曲创作人、演员',
    required: false,
    maxLength: 5000,
  })
  @IsOptional()
  @IsString()
  @MaxLength(5000)
  description?: string;

  @ApiProperty({
    description: '歌手头像URL',
    example: 'https://example.com/avatar.jpg',
    required: false,
  })
  @IsOptional()
  @IsString()
  avatarUrl?: string;

  @ApiProperty({
    description: '出生日期',
    example: '1979-01-18',
    required: false,
  })
  @IsOptional()
  @IsDateString()
  birthDate?: string;

  @ApiProperty({
    description: '国籍',
    example: '中国台湾',
    required: false,
    maxLength: 100,
  })
  @IsOptional()
  @IsString()
  @MaxLength(100)
  nationality?: string;

  @ApiProperty({
    description: '歌手性别',
    example: 'male',
    enum: Gender,
    required: false,
  })
  @IsOptional()
  gender?: Gender;

  @ApiProperty({
    description: '歌手类型',
    example: 'pop',
    enum: SingerType,
    required: false,
  })
  @IsOptional()
  type?: SingerType;
}

/**
 * 歌手列表分页查询参数DTO
 */
export class SingersPaginationQueryDto {
  @ApiProperty({ description: '页码', example: 1, required: false })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  page?: number = 1;

  @ApiProperty({ description: '每页数量', example: 10, required: false })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  limit?: number = 10;

  @ApiProperty({ description: '歌手类型', enum: SingerType, required: false })
  @IsOptional()
  type?: SingerType;

  @ApiProperty({ description: '歌手性别', enum: Gender, required: false })
  @IsOptional()
  gender?: Gender;

  @ApiProperty({ description: '歌手分类', required: false })
  @IsOptional()
  nationality?: string;
}

// 歌手响应DTO
export class SingerResponseDto {
  @ApiProperty({ description: '歌手ID' })
  id: number;

  @ApiProperty({ description: '歌手名称' })
  name: string;

  @ApiProperty({ description: '歌手描述' })
  description?: string;

  @ApiProperty({ description: '歌手头像URL' })
  avatarUrl?: string;

  @ApiProperty({ description: '出生日期' })
  birthDate?: Date;

  @ApiProperty({ description: '国籍' })
  nationality?: string;

  @ApiProperty({ description: '创建时间' })
  createdAt: Date;

  @ApiProperty({ description: '更新时间' })
  updatedAt: Date;

  @ApiProperty({ description: '歌手性别' })
  gender?: Gender;

  @ApiProperty({ description: '歌手类型' })
  type: SingerType;

  @ApiProperty({ description: '歌手的专辑列表', type: [AlbumResponseDto] })
  albums: AlbumResponseDto[];

  @ApiProperty({ description: '歌手的歌曲列表', type: [SongResponseDto] })
  songs: SongResponseDto[];
}
